/*
** Copyright (C) 2015-2016  Michael Roland <mi.roland@fh.hagenberg.at>
**                          FH OÖ Forschungs & Entwicklungs GmbH
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*/
package org.simalliance.openmobileapi.service.terminals.exploit.activities;

import android.app.Activity;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;

import org.simalliance.openmobileapi.service.terminals.exploit.BuildConfig;
import org.simalliance.openmobileapi.service.terminals.exploit.R;

public class AboutActivity extends Activity {
    private static final String LOG_TAG = AboutActivity.class.getSimpleName();
    private static final int[] LINK_BUTTONS = {
            R.id.app_website_mroland,
            R.id.app_website_usmile,
            R.id.app_website_fhooe,
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        getActionBar().setHomeButtonEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);

        for (int linkButtonRes : LINK_BUTTONS) {
            Button linkButton = (Button) findViewById(linkButtonRes);
            if (linkButton != null) {
                linkButton.setMovementMethod(LinkMovementMethod.getInstance());
            }
        }

        TextView buildId = (TextView) findViewById(R.id.app_build);
        if (buildId != null) {
            try {
                android.content.pm.PackageInfo pi = getPackageManager().getPackageInfo(
                        getApplicationInfo().packageName, 0);
                String versionCode = Integer.toString(pi.versionCode);

                buildId.setText(versionCode + (BuildConfig.DEBUG ? getString(R.string.app_build_debug) : ""));
            } catch (Exception e) {
                buildId.setText(R.string.unknown);
            }
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
        }

        return super.onOptionsItemSelected(item);
    }
}
